using System.Windows;
using WPFServices.Models.Domain;
using WPFServices.ViewModels.DomainViewModel.BomInfo;

namespace WPFServices.Views.DomainViews.BomInfo
{
    /// <summary>
    /// BomSelectionWindow.xaml 的交互逻辑
    /// </summary>
    public partial class BomSelectionWindow : Window
    {
        public BomSelectionWindow()
        {
            InitializeComponent();
            var viewModel = new BomSelectionViewModel();
            DataContext = viewModel;

            // 订阅ViewModel的关闭窗口事件
            viewModel.CloseWindow += (result) =>
            {
                try
                {
                    DialogResult = result;
                    Close();
                }
                catch (System.Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine($"关闭窗口时出错: {ex.Message}");
                    Close();
                }
            };
        }

        /// <summary>
        /// 获取选中的BOM
        /// </summary>
        public BomDto SelectedBom
        {
            get
            {
                var viewModel = DataContext as BomSelectionViewModel;
                return viewModel?.SelectedBom;
            }
        }
    }
} 